import numpy as np
# y=sigmoid(wx+b)
class FullyConnect:
    def __init__(self,l_x,l_y) -> None:
        self.weights=np.random.randn(l_y,l_x)/np.sqrt(l_x)
        self.bias=np.random.randn(l_y,1)
        self.l_r=0

    def forward(self,x):
        self.x=x
        self.y=np.array([self.weights.dot(xx)+self.bias for xx in x])
        return self.y


    def backward(self,d):
        print("input daoshu:",d.shape)
        ddx=[dd.dot(xx.T) for xx,dd in zip(self.x,d)]
        self.dw=np.sum(ddx,axis=0)/self.x.shape[0]
        self.db=np.sum(d,axis=0)/self.x.shape[0]
        self.dx=np.array([self.weights.T.dot(dd) for dd in d])
        
        
        self.weights-=self.l_r*self.dw
        self.bias-=self.l_r*self.db
        return self.dx


